
var authorization = myStorage.getItem('memberidToken');
console.log(authorization);

var addrObj = GetQueryString('addrObj');

ltNetwork.tokenGet(configUrl.ADDRESSLIST_URL,'',authorization,function(res){
	console.log(res);
	var data = res.data;
	if(data.length<=0){
		$('.noneaddrDiv').show();
	}else{
		$('#addressTmpl').tmpl(data).appendTo('#addressList');
		
		$('.addrEdit span').on('click',function(){
			var parentDiv = $(this).closest('.addrCon');
			var addressId = parentDiv.attr('id');
			var parentElement = $(this).parents('.addrCon');
			$(this).stop().toggleClass('active');
			parentElement.siblings().find('.addrEdit span').removeClass('active');
			if($(this).hasClass('active')){
				var defaultParam = {
					addressId:addressId
				}
				ltNetwork.tokenPost(configUrl.ADDRESS_DEFAULT_URL,defaultParam,authorization,function(res){
					console.log(res);
				},function(msg){
					console.log(msg);
				});
			}
		});
		
		
		//删除
		$('.delete-addr').on('click',function(){
			var parentDiv = $(this).closest('.addrCon');
			var addressId = parentDiv.attr('id');
			console.log(addressId);
			var addressDelParam = {
				addressId:addressId
			}
			ltNetwork.tokenPost(configUrl.ADDRESSDELETE_URL,addressDelParam,authorization,function(res){
				console.log(res);
				var addrCon = $(this).closest('.addrCon');
				addrCon.remove();
				window.location.reload();
			},function(msg){
				console.log(msg);
			});
		});
		
		//修改
		$('.modify-addr').on('click',function(){
			var parentDiv = $(this).closest('.addrCon');
			var idx = parentDiv.index();
			var addrMsg = JSON.stringify(data[idx]);
			console.log(addrMsg);
			window.location.href = 'modifyAddress.html?addressMsg='+addrMsg;
		});
		//选中地址
		$('.addressDiv').on('click',function(){
			var parentDiv = $(this).closest('.addrCon');
			var idx = parentDiv.index();
			var addrMsg = JSON.stringify(data[idx]);
			window.location.href = '../cartOrderlist2.html?addressMsg='+addrMsg+'&&addrObj='+addrObj;
		});
	}
	
},function(msg){
	console.log(msg);
});
